package example1;

import cn.hutool.core.io.resource.ClassPathResource;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.GroupByElement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectItem;
import net.sf.jsqlparser.util.TablesNamesFinder;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegTest {

    static String REG_PACKAGE = "package\\s+(.*);$";
    static String REG_PUBLIC = "public\\s+class\\s+(\\w+)\\s+";
    static Pattern pattern = Pattern.compile(REG_PACKAGE, Pattern.MULTILINE);
    static Pattern pattern2 = Pattern.compile(REG_PUBLIC, Pattern.MULTILINE);

    @Test
    public void t1() throws Exception {

        String text = FileUtils.readFileToString(new File("C:/Users/yangyang/Desktop/MainActivity.java"), "UTF-8");

        String packageName = "";
        String className = "";
        Matcher matcher = pattern.matcher(text);
        if (matcher.find()) {
            packageName = matcher.group(1);
            System.out.println("The fully qualified class name is: " + packageName);
        }
        Matcher matcher2 = pattern2.matcher(text);
        if (matcher2.find()) {
            className = matcher2.group(1);
            System.out.println("The fully qualified class name is: " + className);
        }
        String fullyQualifiedClassName = String.format("%s.%s", packageName, className);

        System.out.println(fullyQualifiedClassName);
        File dir = new File("/", "1122SyncCode");
        String packagePath = StringUtils.replace(packageName, ".", "/");

        File dirFile = FileUtils.getFile(dir, packagePath);
        File absFile = FileUtils.getFile(dir, packagePath, className + ".java");
        System.out.println(dirFile);
        System.out.println(absFile);

    }

    @Test
    public void t2() throws Exception {


    }

}
